package cn.aran.order.controller;

import cn.aran.order.service.IOrderGoodsDetailService;
import cn.aran.order.domain.OrderGoodsDetail;
import cn.aran.order.query.OrderGoodsDetailQuery;
import cn.aran.basic.utils.AjaxResult;
import cn.aran.basic.utils.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/orderGoodsDetail")
public class OrderGoodsDetailController {
    @Autowired
    public IOrderGoodsDetailService orderGoodsDetailService;


    /**
     * 保存和修改公用的
     * @param orderGoodsDetail  传递的实体
     * @return Ajaxresult转换结果
     */
    @PutMapping
    public AjaxResult addOrUpdate(@RequestBody OrderGoodsDetail orderGoodsDetail){
        try {
            if( orderGoodsDetail.getId()!=null)
                orderGoodsDetailService.update(orderGoodsDetail);
            else
                orderGoodsDetailService.save(orderGoodsDetail);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("保存对象失败！"+e.getMessage());
        }
    }


    /**
    * 删除对象信息
    * @param id
    * @return
    */
    @DeleteMapping(value="/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
        try {
            orderGoodsDetailService.remove(id);
            return AjaxResult.me();
        } catch (Exception e) {
        e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("删除对象失败！"+e.getMessage());
        }
    }

	
    /**
    * 查询单个
    * @Parameters: [id]
    * @Return
    */
    @GetMapping("/{id}")
    public OrderGoodsDetail get(@PathVariable("id")Long id)
    {
        return orderGoodsDetailService.loadById(id);
    }


    /**
    * 查看所有的员工信息
    * @return
    */
    @GetMapping()
    public List<OrderGoodsDetail> list(){

        return orderGoodsDetailService.loadAll();
    }


    /**
    * 分页查询数据
    *
    * @param query 查询对象
    * @return PageList 分页对象
    */
    @PostMapping("/list")
    public PageList<OrderGoodsDetail> json(@RequestBody OrderGoodsDetailQuery query)
    {
        return orderGoodsDetailService.queryData(query);
    }

}
